<?php
/**
 * Error Controller Plugin
 * This plugin take a look in the current module's controllers to find an
 * ErrorController, and if it doesn't find it, it will load the default one.
 *
 * @package     Visi
 * @subpackage  Controller Plugins
 * @author      Luke Visinoni <luke.visinoni@gmail.com>
 * @copyright   (c) 2010 Luke Visinoni <luke.visinoni@gmail.com>
 * @version     $Id$
 */
class Visi_Controller_Plugin_ErrorController extends Zend_Controller_Plugin_Abstract {

    public function preDispatch(Zend_Controller_Request_Abstract $request) {
    
        $front = Zend_Controller_Front::getInstance();
        $errorPlugin = $front->getPlugin('Zend_Controller_Plugin_ErrorHandler');
        $module = $request->getModuleName();
        $defaultModule = $front->getDefaultModule();
        $modulePath = $front->getModuleDirectory();
        $moduleControllerPaths = $front->getControllerDirectory();
        if (array_key_exists($module, $moduleControllerPaths)) {
            if (file_exists($moduleControllerPaths[$module] . '/ErrorController.php')) {
                $errorPlugin->setErrorHandlerModule($module); // this will load the special one
            }
        }
    
    }

}
